package com.example.blog.JwtUtils;

import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
import io.jsonwebtoken.io.Encoders;
import io.jsonwebtoken.security.Keys;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

import javax.crypto.SecretKey;
import java.util.Date;
import java.util.Map;

import static com.example.blog.Utils.JWTUtils.expirationTime;


@SpringBootTest
public class test {
private static SecretKey key;
    @Test
    public  void gentoken(){
         SecretKey secretKey = Keys.secretKeyFor(SignatureAlgorithm.HS256);
        String key = Encoders.BASE64.encode(secretKey.getEncoded());
        System.out.println(key);
        Map<String, Object> claim = Jwts.claims();
        claim.put("username1", "admin1");
        String jwt = Jwts.builder()
                .setClaims(claim)//自定义内容
                .setIssuedAt(new Date())//设置签发时间
                .setExpiration(new Date(System.currentTimeMillis()+expirationTime))//过期时间
                .signWith(secretKey)
                .compact();
        System.out.println(jwt);
    }

}
